package com.wisemoresystem.seal.action.seal.recieve;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_check;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_push;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.service.SealRecieveService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章下发 领取 复核 不符复核
 * 
 * @author hxj
 */
@Controller("ixSealRecieveTwiceCheck")
@Scope("prototype")
@RequestMapping("/ix/seal/recieve/twice")
public class SealDistributeRecieveTwiceCheckAction extends ProjBaseAction {

	@Autowired
	private SealRecieveService service;

	/**
	 * 印章下发 领取 复核 不符复核列表
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = service
				.selectDistributeRecieveTwiceList(WebTools.getCurrentBankId(),
						srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/recieve/twice/list");
		mv.addObject("list", list);
		return mv;
	}

	/**
	 * 转到复核页面
	 * 
	 * @param push_id
	 *            下发id
	 * @return
	 */
	@RequestMapping("/check_form")
	public ModelAndView check_form(String push_id) {

		t_seal_push push = service.findObjById(push_id, t_seal_push.class);
		t_seal seal = service.findObjById(push.getSeal_id(), t_seal.class);

		ModelAndView mv = new ModelAndView("/jsp/seal/recieve/twice/check_form");
		mv.addObject("seal", seal);
		if (ChkTools.isNotNull(seal.getSeal_new_id())) {
			t_seal_new seal_new = service.findObjById(seal.getSeal_new_id(),
					t_seal_new.class);
			if (ChkTools.isNotNull(seal_new/* .getSeal_type_config_id() */)) {
				t_seal_type_config config = service.findObjById(
						seal_new.getSeal_type_config_id(),
						t_seal_type_config.class);
				mv.addObject("config", config);
			}
			mv.addObject("seal_new", seal_new);
		}
		mv.addObject("push_id", push_id);
		return mv;
	}

	/**
	 * 复核
	 * 
	 * @param push_id
	 *            下发id
	 * @param check
	 *            检查信息
	 * @return
	 */
	@RequestMapping("/check")
	public ModelAndView check(String push_id, t_check check) {

		if (service.twice(push_id, check)) {
			super.setTipMsg("复核成功!", Tip.Type.success);
			logT.logH("不符复核", t_seal_push.class, push_id);
		} else {
			super.setTipMsg("复核失败!", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}
